<template>
  <div>
    <button class="sub_btn font14 text_white bg_blue" @click="handleDownload">
      导出
    </button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      header: [],
      tableArr: [],
    };
  },
  components: {
    
  },
  methods: {
    handleSuccess({ results, header }) {
      this.tableArr = results;
      this.header = header;
    },
    handleDownload() {
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = this.header;//导出表头的名字
        const filterVal = this.header;//对应表头的数据的字段
        const data = this.formatJson(filterVal, this.tableArr);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "table-list",
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, data) {
      return data.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
  },
};
</script>

<style>
.sub_btn {
  height: 40px;
  padding: 0 21px;
  border: 0;
  outline: 0;
  cursor: pointer;
  border-radius: 4px;
}
</style>
